//
//  ZGSCartoonDetailsViewController.m
//  MapleLeaf
//
//  Created by dllo on 15/11/26.
//  Copyright © 2015年 AntennaBabyTeam. All rights reserved.
//

#import "ZGSCartoonDetailsViewController.h"

#import "ZGSHomeCartoonModel.h"
#import "ZGSReadModel.h"
#import "ZGSCartoonHistoryModel.h"
#import "ZGSCartoonDetailHeadView.h"
#import "ZGSCartoonDetailFootView.h"
#import "ZGSCartoonDetailCell.h"
#import <AFNetworking.h>
#import <MBProgressHUD.h>
#import <UIImageView+WebCache.h>
#import "DownLoadViewController.h"
#import "WZLReadViewController.h"
#import "SaveTool.h"
@interface ZGSCartoonDetailsViewController ()<UICollectionViewDataSource, UICollectionViewDelegate>



@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, assign) BOOL isShowAll;
@property (nonatomic, assign) BOOL isShowAllPlot;
@property (nonatomic, strong) MBProgressHUD *hud;
@property (nonatomic, strong) UICollectionViewFlowLayout *flowLayout;
@property (nonatomic, strong) UILabel *catalogue;
@property (nonatomic, strong) UILabel *dateLabel;
@property (nonatomic, strong) UIView *lineView;
@property (nonatomic, strong) ZGSHomeCartoonModel *cartoon;
@property (nonatomic, strong) NSMutableArray *readListArr;
@property (nonatomic, assign) NSInteger i;
@end

@implementation ZGSCartoonDetailsViewController



- (void)getConfigData{
    
}





#if 1
- (void)getData {
    
    // 判断是否有本地文件
    if ([SaveTool isHaveInFile:self.albumId type:SaveToolCartoonHistory]) {
        
        ZGSCartoonHistoryModel *cartoonHistory = [[ZGSCartoonHistoryModel alloc] init];
        cartoonHistory = [SaveTool getFile:self.albumId type:SaveToolCartoonHistory];
        // self赋值
        self.readListArr = [NSMutableArray array];
        self.readListArr = cartoonHistory.listArr;
        self.cartoon = cartoonHistory.cartoon;
        self.hSet = cartoonHistory.hSet;
        self.hPage = cartoonHistory.hPage;
        
        [self createViews];
        
        self.title = self.cartoon.name;
        
        [self.collectionView reloadData];
        self.collectionView.hidden = NO;
        [self.hud removeFromSuperview];
        
        [self createData];
        
    }
    else {
        [self createData];
    
    }
}
- (void)createData {
    
    AFNetworkReachabilityManager *netManager = [AFNetworkReachabilityManager sharedManager];
    [netManager startMonitoring];
    [netManager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        if (status == 1 || status == 2) {
            AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
            NSString *strURL = [NSString stringWithFormat:@"http://api.youqudao.com/mhapi/api/album/detail?albumId=%@&customerId=1913463", self.albumId];
            NSLog(@"%@", strURL);
            [manager GET:strURL parameters:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                // 判断数据请求结果
                
                if ([responseObject[@"code"] isEqualToNumber:@101]) {
                    // cartoon赋值
                    NSDictionary *dic = responseObject[@"data"][@"object"];
                    NSLog(@"%@", dic);
                    self.cartoon = [[ZGSHomeCartoonModel alloc] init];
                    [self.cartoon setValuesForKeysWithDictionary:dic];
                    
                    // readListArr赋值
                    NSMutableArray *arr = [NSMutableArray array];
                    arr = responseObject[@"data"][@"list"];
                    self.readListArr = [NSMutableArray array];
                    self.readListArr = [ZGSReadModel baseModelByArr:arr];
                    
                    ZGSCartoonHistoryModel *cartoonHistory = [[ZGSCartoonHistoryModel alloc] init];
                    cartoonHistory.cartoon = self.cartoon;
                    cartoonHistory.listArr = [NSMutableArray array];
                    cartoonHistory.listArr = self.readListArr;
                    cartoonHistory.hSet = self.hSet;
                    cartoonHistory.hPage = self.hPage;
                    
                    [self createViews];
                    // 设置标题
                    self.title = self.cartoon.name;
                    
                    [self.collectionView reloadData];
                    self.collectionView.hidden = NO;
                    
                    [self.hud removeFromSuperview];
                }
                else {
                    [self.hud removeFromSuperview];
                    
                    MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:self.view];
                    [self.view addSubview:hud];
                    hud.mode = MBProgressHUDModeText;
                    hud.labelText = @"数据请求错误 请检查网络";
                    hud.yOffset = 270 * HEIGHT / 667.0;
                    hud.margin = 10 * HEIGHT / 667.0;
                    
                    [hud showAnimated:YES whileExecutingBlock:^{
                        sleep(1.5);
                    } completionBlock:^{
                        [hud removeFromSuperview];
                        
                    }];
                }
                
                
            } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                
                MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:self.view];
                [self.view addSubview:hud];
                hud.mode = MBProgressHUDModeText;
                hud.labelText = @"数据请求错误 请检查网络";
                hud.yOffset = 270 * HEIGHT / 667.0;
                hud.margin = 10 * HEIGHT / 667.0;
                
                [hud showAnimated:YES whileExecutingBlock:^{
                    sleep(1.5);
                } completionBlock:^{
                    [hud removeFromSuperview];
                   
                }];
            }];
            
            // 创建获取本地数据的方法
            [self getConfigData];
        }
        else {
            MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:self.view];
            [self.view addSubview:hud];
            hud.mode = MBProgressHUDModeText;
            hud.labelText = @"数据请求错误 请检查网络";
            hud.yOffset = 270 * HEIGHT / 667.0;
            hud.margin = 10 * HEIGHT / 667.0;
            
            [hud showAnimated:YES whileExecutingBlock:^{
                sleep(1.5);
            } completionBlock:^{
                [hud removeFromSuperview];
                
            }];
        }
    }];
    [netManager stopMonitoring];
    
}
- (void)createViews
{
        // 分割线
        self.lineView = [[UIView alloc] init];
        self.lineView.frame = CGRectMake(0, 435, WIDTH, 2);
        self.lineView.layer.borderWidth = 1;
        self.lineView.layer.borderColor = [[UIColor colorWithRed:0.949f green:0.945f blue:0.957f alpha:1.00f] CGColor];
        [self.collectionView addSubview:self.lineView];
        
        
        // 更新时间
        self.dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(WIDTH - 155 - (WIDTH / 5 - 10)/ 5, 440, 150, 20)];
        self.dateLabel.font = [UIFont systemFontOfSize:13];
        self.dateLabel.textColor = [UIColor colorWithRed:0.624f green:0.624f blue:0.624f alpha:1.00f];
        self.dateLabel.textAlignment = NSTextAlignmentRight;
        // 时间截取
        NSDate *lastDate = [NSDate dateWithTimeIntervalSince1970:[self.cartoon.updateTime integerValue] / 1000];
        NSDateFormatter *df = [[NSDateFormatter alloc] init];
        [df setDateFormat:@"YYYY-MM-dd"];
        NSString *lastTime = [df stringFromDate:lastDate];
        self.dateLabel.text = [NSString stringWithFormat:@"更新时间%@", lastTime];
        [self.collectionView addSubview:self.dateLabel];
        
        
    
}

#pragma mark - viewAction

- (void)viewWillAppear:(BOOL)animated {
    self.navigationController.navigationBarHidden = NO;
    self.navigationController.navigationBar.translucent = NO;
    self.navigationController.navigationBar.hidden = NO;
    self.navigationController.hidesBottomBarWhenPushed = YES;
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:1.000f green:0.267f blue:0.000f alpha:1.00f];
    self.navigationController.navigationBar.alpha = 1;
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                                     [UIColor whiteColor], NSForegroundColorAttributeName , nil]];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
 
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"iconfont-share.png"] style:UIBarButtonItemStylePlain target:self action:@selector(shareAction:)];
    
    
    
    self.isShowAll = NO;
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.catalogue = [[UILabel alloc] initWithFrame:CGRectMake((WIDTH / 5 - 10)/ 5 + 25, 440, WIDTH / 6, 20)];
    self.catalogue.font = [UIFont systemFontOfSize:16];
    self.catalogue.text = @"目录";
    [self.collectionView addSubview:self.catalogue];
   
    
    self.i = 1;
    
    self.hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
    self.collectionView.hidden = YES;
    
    [self getData];
    
}

#pragma mark - lazyLoad

- (UICollectionView *)collectionView {
    if (!_collectionView) {
        // collectionView
        self.flowLayout = [[UICollectionViewFlowLayout alloc] init];
        self.flowLayout.itemSize = CGSizeMake(WIDTH / 5, HEIGHT / 20);
        self.flowLayout.minimumInteritemSpacing = (WIDTH / 5 - 10) / 5;
        self.flowLayout.minimumLineSpacing = (WIDTH / 5 - 10) / 5;
        self.flowLayout.sectionInset = UIEdgeInsetsMake(WIDTH / 5 / 5 + 20, (WIDTH / 5 - 10) / 5 + 4, WIDTH / 5 / 5, (WIDTH / 5 - 10) / 5 + 4);
        
        self.flowLayout.headerReferenceSize = CGSizeMake(WIDTH, 434);
        self.flowLayout.footerReferenceSize = CGSizeMake(WIDTH, HEIGHT / 18);
        
        self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT - 64) collectionViewLayout:self.flowLayout];
        [self.view addSubview:self.collectionView];
        self.collectionView.backgroundColor = [UIColor whiteColor];
        
        // 注册header,footer,cell
        [self.collectionView registerClass:[ZGSCartoonDetailHeadView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"clhReuse"];
        [self.collectionView registerClass:[ZGSCartoonDetailFootView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"clfReuse"];
        [self.collectionView registerClass:[ZGSCartoonDetailCell class] forCellWithReuseIdentifier:@"cdReuse"];
       
        
        self.collectionView.dataSource = self;
        self.collectionView.delegate = self;
        
    }
    return _collectionView;
}

#pragma mark - collectionDateSource & Delegate

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    // 判断显示状态
    if ([self.cartoon.updateSize integerValue] <= 8) {
        NSInteger count = [self.cartoon.updateSize integerValue];
        return count;
    }
    else {
        if (self.isShowAll) {;
            return self.readListArr.count;
        }
        else {
            return 8;
        }
    }
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    ZGSCartoonDetailCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cdReuse" forIndexPath:indexPath];
    
    NSInteger number = self.readListArr.count - indexPath.row;
    cell.numberLable.text = [NSString stringWithFormat:@"%ld", number];
    
    // 判断是否收费
    if ([[self.readListArr[self.readListArr.count - indexPath.item - 1] unLock] integerValue] == 0) {
        cell.numberLable.textColor = [UIColor redColor];
    }
    else {
        cell.numberLable.textColor = [UIColor blackColor];
    }
    
    return cell;
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
    
    // footer
    if (kind == UICollectionElementKindSectionFooter) {
        ZGSCartoonDetailFootView *footReusableView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"clfReuse" forIndexPath:indexPath];
        [footReusableView.allListButton addTarget:self action:@selector(showAllAction:) forControlEvents:UIControlEventTouchUpInside];
        return footReusableView;
    }
    // header
    else {
        ZGSCartoonDetailHeadView *headReusableView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"clhReuse" forIndexPath:indexPath];
        
        // header赋值
        NSString *converPic = [self.cartoon.coverPic stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        [headReusableView.picView sd_setImageWithURL:[NSURL URLWithString:converPic] placeholderImage:[UIImage imageNamed:@"backgroundImage.png"]];
        headReusableView.titleLabel.text = self.cartoon.name;
        headReusableView.typeLabel.text = [NSString stringWithFormat:@"类型:%@", self.cartoon.label];
        headReusableView.authorLabel.text = [NSString stringWithFormat:@"作者:%@", self.cartoon.author];
        headReusableView.companyLabel.text = [NSString stringWithFormat:@"发行商:%@", self.cartoon.authorName];
        
        // 判断连载状态
        if ([self.cartoon.status integerValue] == 0) {
            NSString *statusStr = [NSString stringWithFormat:@"更新到%@话 (连载中)", self.cartoon.updateSize];
            NSMutableAttributedString *tMutaString = [[NSMutableAttributedString alloc] initWithString:statusStr];
            [tMutaString addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(statusStr.length - 5, 5)];
            [tMutaString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:17] range:NSMakeRange(statusStr.length - 5, 5)];
            headReusableView.totalLabel.attributedText = tMutaString;
        }
        else {
            NSString *statusStr = [NSString stringWithFormat:@"共%@话 (已完结)", self.cartoon.updateSize];
            NSMutableAttributedString *tMutaString = [[NSMutableAttributedString alloc] initWithString:statusStr];
            [tMutaString addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(statusStr.length - 5, 5)];
            [tMutaString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:17] range:NSMakeRange(statusStr.length - 5, 5)];
            headReusableView.totalLabel.attributedText = tMutaString;
            
        }
        
        // 阅读按钮
        if (self.hSet == - 1) {
            [headReusableView.readButton setTitle:[NSString stringWithFormat:@"续看1话"] forState:UIControlStateNormal];
        }
        
        else if (self.hSet) {
            [headReusableView.readButton setTitle:[NSString stringWithFormat:@"续看%ld话", self.hSet + 1] forState:UIControlStateNormal];
        }
        [headReusableView.readButton addTarget:self action:@selector(startReadAction:) forControlEvents:UIControlEventTouchUpInside];
        headReusableView.readButton.tag = 6000;
        
//        // 判断收藏状态
        if (![SaveTool isHaveInFile:self.cartoon type:SaveToolCartoonBookCase]) {
            [headReusableView.collectionButton setTitle:@"添加收藏" forState:UIControlStateNormal];
        }
        else {
            [headReusableView.collectionButton setTitle:@"取消收藏" forState:UIControlStateNormal];
        }
        
        [headReusableView.collectionButton addTarget:self action:@selector(collectionAction:) forControlEvents:UIControlEventTouchUpInside];
        
        // 判断收费状态
        if ([self.cartoon.price floatValue] > 0) {
            
            headReusableView.isFreeImageView.image = [UIImage imageNamed:@"iconfont-shoufeibaojia.png"];
            headReusableView.statusLabel.text = @"部分章节收费";
        }
        else {
            headReusableView.isFreeImageView.image = [UIImage imageNamed:@"iconfont-mianfeibeian48x48.png"];
            headReusableView.statusLabel.text = @"免费";
        }
        
        // 分享按钮
        [headReusableView.shareButton addTarget:self action:@selector(shareAction:) forControlEvents:UIControlEventTouchUpInside];
        
       
        // 下载
        headReusableView.papularLabel.text = @"下载";
        headReusableView.hotImageView.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pushDownLoadView:)];
        [headReusableView.hotImageView addGestureRecognizer:tap];
        
    
        
        // 介绍
        headReusableView.plotLabel.text = self.cartoon.descriptions;
        headReusableView.plotLabel.tag = 2000;
        headReusableView.allPlotLabel.text = self.cartoon.descriptions;
        headReusableView.allPlotLabel.tag = 2001;
        headReusableView.showAllPlotButton.tag = 2002;
        headReusableView.notShowAllPlotButton.tag = 2003;
        
        // 展开收起按钮
        [headReusableView.showAllPlotButton addTarget:self action:@selector(showAllPlotAction:) forControlEvents:UIControlEventTouchUpInside];
        [headReusableView.notShowAllPlotButton addTarget:self action:@selector(showAllPlotAction:) forControlEvents:UIControlEventTouchUpInside];
//        headReusableView.showAllPlotButton
        
        return headReusableView;
        
    }
    
}
- (void)pushDownLoadView:(UITapGestureRecognizer *)tap
{
    DownLoadViewController *VC = [[DownLoadViewController alloc] init];
    [self.navigationController pushViewController:VC animated:YES];
    VC.dataArr = self.readListArr;
    VC.picStr = self.cartoon.coverPic;
    VC.number = self.cartoon.updateSize;
    VC.name = self.cartoon.name;
    
    
    
    
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    ZGSCartoonDetailCell *cell = (ZGSCartoonDetailCell *)[collectionView cellForItemAtIndexPath:indexPath];
        if ([[self.readListArr[self.readListArr.count - indexPath.item - 1] unLock] integerValue] == 0)
        {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"该章节为收费章节" delegate:nil cancelButtonTitle:@"确认" otherButtonTitles:nil, nil];
            [alert show];
        }
        else
        {
            NSLog(@"%@", self.readListArr[indexPath.row]);
            cell.numberLable.isClick = YES;
            WZLReadViewController *VC = [[WZLReadViewController alloc] init];
            
            [self.navigationController pushViewController:VC animated:YES];
            VC.model = self.readListArr[self.readListArr.count - indexPath.item - 1];
            VC.numOfCartoon = self.readListArr.count - indexPath.item - 1;
            NSLog(@"%ld", VC.numOfCartoon);
            VC.readArr = self.readListArr;
            
        }
}



#pragma mark header & footer ButtonAction

- (void)showAllAction:(UIButton *)button {
    
    // 是否显示全部章节
    if ([self.cartoon.updateSize integerValue] <= 8) {
        [button setTitle:@"已是全部章节" forState:UIControlStateNormal];
    }
    else {
        if (self.isShowAll) {
            [button setTitle:@"查看全部章节" forState:UIControlStateNormal];
            self.isShowAll = !self.isShowAll;
            [self.collectionView reloadData];
        }
        else {
            [button setTitle:@"查看部分章节" forState:UIControlStateNormal];
            self.isShowAll = !self.isShowAll;
            [self.collectionView reloadData];
        }
    }
 
    
}




// 介绍操作
- (void)showAllPlotAction:(UIButton *)button {
    
    // 展开介绍
    if (!self.isShowAllPlot) {
        self.isShowAllPlot = !self.isShowAllPlot;
        UILabel *label = (UILabel *)[self.view viewWithTag:2000];
        UILabel *allLabel = (UILabel *)[self.view viewWithTag:2001];
        UIButton *showAllPlotButton = (UIButton *)[self.view viewWithTag:2002];
        UIButton *notShowAllPlotButton = (UIButton *)[self.view viewWithTag:2003];
        allLabel.numberOfLines = 0;
        //展开的时候自适应
        NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:14], NSFontAttributeName, nil];
        CGRect rect = [allLabel.text boundingRectWithSize:CGSizeMake(WIDTH - ((WIDTH / 5 - 10) / 5 + 5) * 2, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
        allLabel.frame = CGRectMake((WIDTH / 5 - 10) / 5 + 5, 380, WIDTH - ((WIDTH / 5 - 10) / 5 + 5) * 2, rect.size.height);
        notShowAllPlotButton.frame = CGRectMake((WIDTH / 5 - 10) / 5 + 5, 380 + rect.size.height, WIDTH - ((WIDTH / 5 - 10) / 5 + 5) * 2, 20);
        self.flowLayout.headerReferenceSize = CGSizeMake(375, 434 + rect.size.height - 34);
        self.catalogue.frame = CGRectMake((WIDTH / 5 - 10)/ 5 + 25, 440 + rect.size.height - 34, WIDTH / 6, 20);
        self.dateLabel.frame = CGRectMake(WIDTH - 155 - (WIDTH / 5 - 10)/ 5, 440 + rect.size.height - 34, 150, 20);
        self.lineView.frame = CGRectMake(0, 435 + rect.size.height - 34, WIDTH, 2);
        
        label.hidden = YES;
        showAllPlotButton.hidden = YES;
        allLabel.hidden = NO;
        notShowAllPlotButton.hidden = NO;
//        NSDictionary *dic1 = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:14],NSFontAttributeName, nil];
        
        
    }
    
    // 收起介绍
    else {
        
        self.isShowAllPlot = !self.isShowAllPlot;
        UILabel *label = (UILabel *)[self.view viewWithTag:2000];
        UILabel *allLabel = (UILabel *)[self.view viewWithTag:2001];
        UIButton *showAllPlotButton = (UIButton *)[self.view viewWithTag:2002];
        UIButton *notShowAllPlotButton = (UIButton *)[self.view viewWithTag:2003];
        label.hidden = NO;
        showAllPlotButton.hidden = NO;
        allLabel.hidden = YES;
        notShowAllPlotButton.hidden = YES;
        self.flowLayout.headerReferenceSize = CGSizeMake(375, 434);
        self.catalogue.frame = CGRectMake((WIDTH / 5 - 10)/ 5 + 25, 440, WIDTH / 6, 20);
        self.dateLabel.frame = CGRectMake(WIDTH - 155 - (WIDTH / 5 - 10)/ 5, 440, 150, 20);
        self.lineView.frame = CGRectMake(0, 435, WIDTH, 2);
    }
}

// 阅读
- (void)startReadAction:(UIButton *)button {
    if ([[self.readListArr[0] unLock] integerValue] == 0) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"抱歉" message:@"该章节为收费章节" delegate:nil cancelButtonTitle:@"确认" otherButtonTitles:nil, nil];
        [alert show];
    }
    else {
        WZLReadViewController *rcVC = [[WZLReadViewController alloc] init];
        rcVC.readArr = self.readListArr;
        rcVC.numOfCartoon = 0;
        rcVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:rcVC animated:YES];
   
    }
    
    
}

// 收藏
- (void)collectionAction:(UIButton *)button {
    if ([button.titleLabel.text isEqualToString:@"添加收藏"]) {
        [button setTitle:@"取消收藏" forState:UIControlStateNormal];
        ZGSCartoonHistoryModel *cartoonHistory = [[ZGSCartoonHistoryModel alloc] init];
        cartoonHistory.cartoon = self.cartoon;
        cartoonHistory.listArr = [NSMutableArray array];
        cartoonHistory.listArr = self.readListArr;
        cartoonHistory.hSet = self.hSet;
        cartoonHistory.hPage = self.hPage;
        [SaveTool saveFileToPlist:cartoonHistory type:SaveToolCartoonBookCase];
    }
    else if ([button.titleLabel.text isEqualToString:@"取消收藏"]) {
        [button setTitle:@"添加收藏" forState:UIControlStateNormal];
        ZGSCartoonHistoryModel *cartoonHistory = [[ZGSCartoonHistoryModel alloc] init];
        cartoonHistory.cartoon = self.cartoon;
        cartoonHistory.listArr = [NSMutableArray array];
        cartoonHistory.listArr = self.readListArr;
        cartoonHistory.hSet = self.hSet;
        cartoonHistory.hPage = self.hPage;
        [SaveTool cancleFileInPlist:cartoonHistory type:SaveToolCartoonBookCase];
    }
    
}

- (void)shareAction:(UIButton *)button {
    // 分享网络图片
//    [[UMSocialData defaultData].urlResource setResourceType:UMSocialUrlResourceTypeImage url:
//     self.cartoon.coverPic];
//    
//    [UMSocialSnsService presentSnsIconSheetView:self
//                                         appKey:@"56373f8a67e58e6ce90004bb"
//                                      shareText:[NSString stringWithFormat:@"我在用枫叶岛漫画观看《%@》", self.cartoon.name]
//                                     shareImage:nil
//                                shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToWechatSession,UMShareToQQ,nil]
//                                       delegate:self];
}


#pragma mark - UMDelegate



#pragma mark - Delegate get value

- (void)getValue:(NSInteger)hSet hPage:(NSInteger)hPage {
    UIButton *button = (UIButton *)[self.view viewWithTag:6000];
    self.hSet = hSet;
    self.hPage = hPage;
    [button setTitle:[NSString stringWithFormat:@"续看%ld话", hSet + 1] forState:UIControlStateNormal];
    [self.collectionView reloadData];
}

#endif



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
